function on_ready_state(req, onload) {
  if (req.readyState==4) {
    if (req.status==200 || req.status==0) {
      onload(req);
    } else {
      error(req);
    }
  }
}
function ajax(url,method,params,onload) {
  var req;
  if (window.XMLHttpRequest) {
    req=new XMLHttpRequest();
  } else if (typeof ActiveXObject != undefined) {
    req=new ActiveXObject("Microsoft.XMLHTTP");
  } else req = new ActiveXObject("Msxml2.XMLHTTP");
  if (req) {
    try {
      if (onload) {
        req.onreadystatechange=function() { on_ready_state(req, onload) };
      }
      req.open(method,url,true);
      req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
      req.send(params);
    } catch (err) {
      error(req);
    }
  }
}
function error(req) {
  alert("\n\nreadyState:"+req.readyState
    +"\nstatus: "+req.status
    +"\nheaders: "+req.getAllResponseHeaders());
}
